
const { contextBridge, ipcRenderer } = require('electron')

// window.ipcRenderer=ipcRenderer

// window.addEventListener('DOMContentLoaded', () => {
//     document.getElementById('minimize').addEventListener('click', () => {
//         console.log('hello vscode!')
//         ipcRenderer.send('window-min');
//     })

//     document.getElementById('close').addEventListener('click', () => {
//         console.log('hello vscode!')
//         ipcRenderer.send('window-close');
//     })

// })

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('ipc', {
    send: (channel, data) => {
      // whitelist channels
      let validChannels = ['window-min', 'window-close']
      if (validChannels.includes(channel)) {
        ipcRenderer.send(channel, data)
      }
    },
    receive: (channel, func) => {
      let validChannels = ['fromMain']
      if (validChannels.includes(channel)) {
        // Deliberately strip event as it includes `sender`
        ipcRenderer.on(channel, (event, ...args) => func(...args))
      }
    }
  })